package ${basePackage}.controller;

import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.model.${modelNameUpperCamel}Criteria;
import ${basePackage}.service.${modelNameUpperCamel}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("${baseRequestMapping}s")
public class ${modelNameUpperCamel}Controller {

    @Autowired
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @PostMapping
    public ResponseResult add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable ${type} id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.updateBySelective(${modelNameLowerCamel});
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable ${type} id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return ResultGenerator.generatorSuccess(${modelNameLowerCamel});
    }

    @GetMapping
    public ResponseResult list(${modelNameUpperCamel}Criteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
